import React, { Component } from 'react';
import ReactDom from 'react-dom';
import util from "@/common/util";
import turnplate from "@/common/turnplate";
import layer from "@/common/layer";
import Rate from '@/Components/rate';
import DDView from '@/Components/ddview';
import InlinePicker from '@/Components/inlinepicker';
import ReactSwiper from 'reactjs-swiper';
import axios from 'axios';
import { relative } from 'path';
import jquery from 'jquery';


class Prizerecord extends Component {
    constructor(props) {
        super(props);
        this.state = {
            prize: '一场空'
        }
    }

    async isprize() {
        var openid = sessionStorage.getItem("openid")
        let res = await util.rjax({
            url: 'prizeUser/selectUserPrize?openId=' + openid,
            type: 'get',
        }).catch((e) => {
            if (e) {
                jquery('.noprize').show()
                jquery('.prizes').hide()
            }
        })

        if (res) {//请求和响应code都为200
            if (res.isPrize === 0) {
                jquery('.noprize').show()
                jquery('.prizes').hide()
            } else if (res.isPrize === 1) {
                jquery('.noprize').hide()
                jquery('.prizes').show()
                this.setState({ prize: res.prizeName });
            }
        }
    }

    componentDidMount() {
        this.isprize()
    }

    render() {
        return (
            <div>
                <div id="prizerecord">

                    <div className="noprize">
                        <img className="noimg" src="/assets/wechat/noprize.png" alt="" />
                        <p>您还没有中奖</p>
                    </div>

                    <div className="prizes">
                        <img src="/assets/wechat/prizes.png" alt="" />
                        <h5>———— 我的中奖记录 ————</h5>
                        <p>
                            <span>奖品:</span>
                            <span>抽中<i>{this.state.prize}</i>&nbsp;x1</span>
                        </p>
                        <a className="goimprove" href="./improveinfo.html">前往完善信息 &gt;&gt;</a>
                    </div>

                </div>
            </div >
        )
    }
}
ReactDom.render(<Prizerecord />, document.getElementById("app"));